package com.lock;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.CountDownLatch;

/**
 * @author:wesley
 */
public class LockMainTest {

    private static Logger logger = LoggerFactory.getLogger(LockMainTest.class);


    private static int thread_num = 3;

    public static CountDownLatch countDownLatch = new CountDownLatch(thread_num);



    public static void main(String[] args){


        for (int i = 0; i < thread_num; i++) {

            final int threanId = i;

            new Thread(){
                @Override
                public void run() {
                    logger.info("当前线程： "+Thread.currentThread().getName());
                    try {
                        new LockService().doService(new DoServiceTemplate() {
                            public void doService() {
                                logger.info("我要修改文件...."+threanId);
                            }
                        });
                    }catch (Exception e) {
                        logger.error(threanId + "异常...");
                        e.printStackTrace();
                    }
                }
            }.start();
        }


        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.info("所有线程运行完毕...");
    }

}
